package main.java.org.controller;
import lombok.extern.slf4j.Slf4j;
import main.java.Exam.pojo.tableDTO.QuesttionDTO;
import main.java.Exam.pojo.tableVO.PageResultVO;
import main.java.Exam.pojo.tableVO.QuesttionVO;
import main.java.org.result.Result;
import main.java.org.service.questionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/test")
@Slf4j
public class QuestionController {
@Autowired
private questionService questionService;


    // 修改题目
    @PostMapping("/edit")
    public Result<String> createquestion(@RequestBody QuesttionDTO questionDTO ) {
        log.info("修改题目");
        //修改题目的逻辑
        questionService.alter(questionDTO);
        return Result.success("题目编辑成功");
    }

   //删除题目
    @PostMapping("/delete")
    public Result<String> delete(@RequestBody QuesttionDTO questionDTO ) {
        log.info("删除题目");
        questionService.delete(questionDTO);
        log.info("题目删除成功");
        return Result.success("题目删除成功成功");
    }

   //添加题目
   @PostMapping("addation")
   public Result addation(@RequestBody QuesttionDTO questtionDTO){
        log.info("题目添加");

      questionService.createquestion(questtionDTO);
      return Result.success("题目添加成功");
   }
    //查询题目
    @GetMapping("/getdata")
    public Result<PageResultVO<QuesttionVO>> getSimplePage(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "100") Integer pageSize) {

        PageResultVO<QuesttionVO> pageVO = questionService.getPage(pageNum, pageSize);
        return Result.success(pageVO); // 此时返回类型匹配
    }

    //查询单个题目
    @GetMapping("/getquestion")
    public Result<QuesttionDTO> getquestion(@RequestParam Integer questionId,@RequestParam Integer type){
        log.info("查看单个题目");
        QuesttionDTO questtionDTO=questionService.getquestion(questionId,type);
        return Result.success(questtionDTO);
    }
}
